package com.fyl.aop;

import org.springframework.aop.support.StaticMethodMatcher;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class RequestMappingMethodMatcher extends StaticMethodMatcher {
    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        int modifiers = method.getModifiers();
        if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
            Annotation[] annotations = method.getDeclaredAnnotations();
            for (Annotation anno : annotations) {
                if (anno.annotationType().equals(RequestMapping.class) ||
                        anno.annotationType().isAnnotationPresent(RequestMapping.class)) {
                    return true;
                }
            }
        }
        return false;
    }
}
